import api from "@/api";

var mp3ToM3u8 = {
	init:function () {
		this.initEvent()
	},
	initEvent:function () {
		this.uploadInput = $("#uploadfile");
		$(".upload-bar").click(() => {
			$(".download").removeClass("show")
			this.uploadInput.click()
		})
		this.uploadInput.change(this.uploadFile.bind(this))


		$(".view-btn").click(function () {
			let docName = $("#doc-name").val();
			if(!docName) return;
			if(docName == "每课"){
				location.href = "/doc";
				return
			}
			alertTips.toast("您输入的暗号不存在")
		})
	},
	uploadFile:async function (e) {
		let file = e.target.files[0];
		this.uploadInput.val("");
		let formData = new FormData();
		formData.append("file",file);
		alertTips.loading("处理中...")
		let result = await api.upload("/file/upload",formData);
		alertTips.hide();
		if(result.path){
			$(".download").addClass("show");
			$(".duration-text").text(result.duration)
			$(".download-text").attr("href",result.path)
		}
		
	}
}

mp3ToM3u8.init();